//
//  YLDefaultOrderIDConverter.swift
//  Distance
//
//  Created by changhe on 2025/4/27.
//


/// 默认的订单ID转换器实现
///
/// 将32位订单号转换为标准UUID格式，格式为：XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
public class YLOrderIDConverterTool: YLOrderIDConverter {
	public init() {}
	
	public func toUUID(_ orderId: String) -> String {
		// 确保输入长度为32个字符
		guard orderId.count == 32 else {
			debugPrint("[toUUID] 订单号长度需要是32个字符")
			return orderId
		}
		
		let formatted = orderId.replacingOccurrences(of: "^(.{8})(.{4})(.{4})(.{4})(.{12})$",
												with: "$1-$2-$3-$4-$5",
												options: .regularExpression)
		return formatted
	}
	
	public func fromUUID(_ uuid: String) -> String {
		guard uuid.count == 32 else {
			debugPrint("[fromUUID] 订单号长度需要是32个字符")
			return uuid
		}
		return uuid.replacingOccurrences(of: "-", with: "").lowercased()
	}
}
